<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of News
 *
 * @author Vu
 */
include APPLICATION_PATH."/models/base/NewsBase.php";
class Model_News extends Model_NewsBase{
    //put your code here
}
class Model_NewsMapper extends Model_NewsMapperBase{
    public static function publicpublished($module){
        $entries = array();
        if($module==1){
            $db = Zend_Db_Table::getDefaultAdapter();
            $select=$db->select()
                    ->from('news')
                    ->where('status=1 and (news_cat_id=1 or news_cat_id=3)')
                    ->order(array('event desc','created desc'));
            $stmt=$select->query();
            $rows = $stmt->fetchAll(PDO::FETCH_CLASS);
            $stmt->closeCursor();
            foreach ($rows as $row) {
                $entry = new Model_News();
                $entry->setId($row->id)
                        ->setId($row->id)
                        ->setTitle($row->title)
                        ->setCreated($row->created)
                        ->setCreated_By($row->created_by)
                        ->setModified($row->modified)
                        ->setModified_By($row->modified_by)
                        ->setDescription($row->description)
                        ->setContent($row->content)
                        ->setEvent($row->event)
                        ->setStatus($row->status)
                        ->setNews_Cat_Id($row->news_cat_id);
                $entries[] = $entry;
            }
            return $entries; 
        } else if($module ==2){
            $db = Zend_Db_Table::getDefaultAdapter();
            $select=$db->select()
                    ->from('news') 
                    ->where('status=1 and (news_cat_id=1 or news_cat_id=2)')
                    ->order(array('event desc','created desc'));
            $stmt=$select->query();
            $rows = $stmt->fetchAll(PDO::FETCH_CLASS);
            $stmt->closeCursor();
            foreach ($rows as $row) {
                $entry = new Model_News();
                $entry->setId($row->id)
                        ->setId($row->id)
                        ->setTitle($row->title)
                        ->setCreated($row->created)
                        ->setCreated_By($row->created_by)
                        ->setModified($row->modified)
                        ->setModified_By($row->modified_by)
                        ->setDescription($row->description)
                        ->setContent($row->content)
                        ->setEvent($row->event)
                        ->setStatus($row->status)
                        ->setNews_Cat_Id($row->news_cat_id);
                $entries[] = $entry;
            }
            return $entries;
        }
    }
    //truyen $module = 2 ko dung
    
    public static function publicpublished5tin($module){
        $entries = array();
        if($module==1){
            $db = Zend_Db_Table::getDefaultAdapter();
//            $select=$db->select()
//                    ->from('news')
//                    ->where('status=1 and news_cat_id=1')
//                    ->order(array('event desc','created desc'))
//                    ->limit(0,5);
//            
//            $stmt=$select->query();
            $stmt=$db->query("SELECT * from news where status =1 and (news_cat_id=1 or news_cat_id=3) order by event,created desc limit 0,5");
            $rows = $stmt->fetchAll(PDO::FETCH_CLASS);
            $stmt->closeCursor();
            foreach ($rows as $row) {
                $entry = new Model_News();
                $entry->setId($row->id)
                        ->setId($row->id)
                        ->setTitle($row->title)
                        ->setCreated($row->created)
                        ->setCreated_By($row->created_by)
                        ->setModified($row->modified)
                        ->setModified_By($row->modified_by)
                        ->setDescription($row->description)
                        ->setContent($row->content)
                        ->setEvent($row->event)
                        ->setStatus($row->status)
                        ->setNews_Cat_Id($row->news_cat_id);
                $entries[] = $entry;
            }
            return $entries; 
        } else if($module ==2){
            $db = Zend_Db_Table::getDefaultAdapter();
            $stmt=$db->query("SELECT * from news where status =1 and (news_cat_id=1 or news_cat_id=2) order by event,created desc limit 0,5");
            $rows = $stmt->fetchAll(PDO::FETCH_CLASS);
            $stmt->closeCursor();
            foreach ($rows as $row) {
                $entry = new Model_News();
                $entry->setId($row->id)
                        ->setId($row->id)
                        ->setTitle($row->title)
                        ->setCreated($row->created)
                        ->setCreated_By($row->created_by)
                        ->setModified($row->modified)
                        ->setModified_By($row->modified_by)
                        ->setDescription($row->description)
                        ->setContent($row->content)
                        ->setEvent($row->event)
                        ->setStatus($row->status)
                        ->setNews_Cat_Id($row->news_cat_id);
                $entries[] = $entry;
            }
            return $entries;
        }
    }
}
